package com.atguigu.paths;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

/**
 * className: PathDemo1
 * description:
 * date: 2023/3/10 0010-14:51
 * <p>
 * project: nio
 * package: com.atguigu.paths
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public class PathDemo1 {

    public static void main(String[] args) {
        // 创建 path 实例
        Path path = Paths.get(Objects.requireNonNull(PathDemo1.class.getClassLoader().getResource("01.txt")).getPath().substring(1));

        // 创建相对路径
        // 代码 1
        Path projects = Paths.get(Objects.requireNonNull(PathDemo1.class.getClassLoader().getResource("")).getPath().substring(1), "projects");

        // 代码 2
        Path file = Paths.get(Objects.requireNonNull(PathDemo1.class.getClassLoader().getResource("")).getPath().substring(1), "projects/002.txt");

        String originalPath = Objects.requireNonNull(PathDemo1.class.getClassLoader().getResource("")).getPath().substring(1) + "/projects/../yygh-project/";

        Path path1 = Paths.get(originalPath);
        System.out.println("path1 = " + path1);

        Path path2 = path1.normalize();
        System.out.println("path2 = " + path2);
    }
}
